package com.zxu.test.studyapp;

import android.view.View;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.zxu.test.base.BaseViewModel;
import com.zxu.test.util.DoubleClickUtils;
import com.zxu.test.util.Event;

public class MainViewModel extends BaseViewModel {

    public final ObservableField<String> btnEvent = new ObservableField<>();
    public final ObservableField<Event<String>> clearEvent = new ObservableField<>();
    public final ObservableField<Event<String>> cancelEvent = new ObservableField<>();
    public final ObservableField<Event<String>> saveEvent = new ObservableField<>();
    private final MutableLiveData<Event<Object>> btBroadcastEvent = new MutableLiveData<>();

    MutableLiveData<Event<Object>> getBroadcastCommand() {
        return btBroadcastEvent;
    }

    public MainViewModel() {
        start();
    }

    private void start() {
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.bt))
                    btnEvent.set("sss");
                break;
            case R.id.clear:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.clear))
                    clearEvent.set(new Event<>(""));
                break;
            case R.id.cancel:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.cancel))
                    cancelEvent.set(new Event<>(""));
                break;
            case R.id.save:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.save))
                    saveEvent.set(new Event<>(""));
                break;
            case R.id.btBroadcast:
                if (!DoubleClickUtils.isFastDoubleClick(R.id.btBroadcast))
                    btBroadcastEvent.setValue(new Event<>("aaa"));
                break;

        }
    }

}
